import { _decorator, Component, sys } from 'cc';
import { tgxUIMgr, tgxUIAlert, tgxSceneUtil } from '../../core_tgx/tgx';
import { SceneDef } from '../../scripts/SceneDef';
import { UserMgr } from './UserMgr';
import { SubGameMgr } from './SubGameMgr';
import { LobbyGameMgr } from './LobbyGameMgr';
import { UIChat } from '../ui_chat/UIChat';
import { UIAnnouncement } from '../ui_announcement/UIAnnouncement';
const { ccclass, property } = _decorator;

@ccclass('LobbyScene')
export class LobbyScene extends Component {
    async start() {
        if (!UserMgr.inst.userId) {
            tgxSceneUtil.loadScene(SceneDef.START);
            return;
        }

        SubGameMgr.inst.unloadCurrent();

        tgxUIMgr.inst.hideAll();

        tgxUIMgr.inst.showUI(UIAnnouncement)

        let ret = await LobbyGameMgr.inst.connectToLobby();
        if (ret.isSucc) {
            tgxUIMgr.inst.showUI(UIChat);
        }
    }

    onBtnSubGameClicked(event, gameType: string) {
        if (gameType == 'billiards' || gameType == 'gomoku') {
            SubGameMgr.inst.loadSubGame(gameType, true);
        }
        else if (gameType == 'more') {
            tgxUIAlert.show("前往 TGX 主页查看更多案例.", true).onClick(bTrue => {
                if (bTrue) {
                    sys.openURL('https://github.com/MrKylinGithub/OpenTGX/blob/main/README-CN.md');
                }
            });
        }
        else {
            tgxUIAlert.show("研发团队加班中，敬请期待!");
        }
    }

    update(deltaTime: number) {

    }
}